﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.Regions;
using Presentation.Module.Security.Interfaces.Views;
using Presentation.Shell.Interfaces;

namespace Presentation.Module.Security
{
    /// <summary>
    /// Interaction logic for UserManagementLandingPage.xaml
    /// </summary>
    public partial class UserManagementLandingPage : UserControl, IModuleLandingPage
    {
        private readonly IRegionManager _regionManager;
        private readonly IUserView _userView;
        private readonly IRoleView _roleView;

        public UserManagementLandingPage(IRegionManager regionManager, IUserView userView, IRoleView roleView)
        {
            InitializeComponent();

            this._regionManager = regionManager;
            this._userView = userView;
            this._roleView = roleView;

            this._regionManager.Regions["MainRegion"].Add(this._userView);
            this._regionManager.Regions["MainRegion"].Add(this._roleView);

            _userView.ViewExit += ExitChildView;
            _roleView.ViewExit += ExitChildView;

        }

        public void LoadUserView(object sender, RoutedEventArgs e)
        {
            this._regionManager.Regions["MainRegion"].Activate(this._userView);
        }

        public void LoadRoleView(object sender, RoutedEventArgs e)
        {
            this._regionManager.Regions["MainRegion"].Activate(this._roleView);        
        }

        private void ExitChildView()
        {
            this._regionManager.Regions["MainRegion"].Activate(this);
        }

        public object ParentView { get; set; }

        /// <summary>
        /// Occurs when [view exit].
        /// </summary>
        public event Shell.Interfaces.ViewExit ViewExit;

        /// <summary>
        /// Cancels the specified sender.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void Cancel(object sender, System.Windows.RoutedEventArgs e)
        {
            if (this.ViewExit != null)
            {
                this.ViewExit.Invoke();
            }
        }
    }
}
